<?php


namespace App\Service;

use App\Common\Tools\DbTools;
use App\Library\Common;
use App\Model\ProductAudit;
use App\Model\Product;
use App\Model\ProductAuditRefuse;
use Hyperf\DbConnection\Db;
use mysql_xdevapi\Exception;

/**
 * 商品审核
 * Class ProductAuditService
 * @package App\Service
 */
class ProductAuditRefuseService extends BaseService
{



    /**
     *
     * 驳回原因
     * @param int $audit
     * @param int $type
     * @param array $reasons
     * @param string $tips  1驳回 2下架
     * @return bool
     */
    public function refuse_insert($audit,$reasons,$tips,$type=1)
    {
//        $this->update_insert(
////            ['audit_id'=>$audit,'type'=>$type],
//            [],
//            [
//                'audit_id'=>$audit,
//                'reason_json'=>json_encode($reasons),
//                'tips'=>$tips,
//                'type'=>$type,
//            ]
//        );
        ProductAuditRefuse::query()->insert(Common::filter_null([
            'audit_id'=>$audit,
            'reason_json'=>json_encode($reasons),
            'tips'=>$tips,
            'type'=>$type,
        ]));
        return true;

    }
    /**
     *
     * 驳回原因
     * @param int $product_id
     * @param int $type
     * @return object
     */
    public function first_refuse($product_id,$type=1)
    {
        return ProductAuditRefuse::query()
            ->leftJoin('fly_product_audit as pa','pa.id','=','fly_product_audit_refuse.audit_id')
            ->where('pa.product_id',$product_id)
            ->where('fly_product_audit_refuse.type',$type)
            ->orderBy('pa.id','DESC')
            ->first(['pa.id','fly_product_audit_refuse.reason_json','fly_product_audit_refuse.tips'])->toArray();

    }

}